const db = wx.cloud.database()
const collectionName = 'comment'
export default {
  getList: async function ({
    pageNum,
    pageSize,
    activeId
  }) {
    var skip = (pageNum - 1) * pageSize
    var matchObj = {activeId}
    let res = await db.collection(collectionName).aggregate()
      .match(matchObj)
      .sort({
        createDate: -1
      })
      .skip(skip)

      .limit(pageSize)
      .end()

    return res.list
  },
  add: async function (data) {
    data.createDate = new Date()
    return await db.collection(collectionName).add({
      data: data
    })
  }
}